package org.eng2.model;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class MesasAtivasDAO {
	
	protected ArrayList<MesasAtivas> getAll() throws SQLException {
		PreparedStatement ps;
		MesasAtivas ma = null;
		
		StringBuilder sql = new StringBuilder();
		sql.append("select ma.id mesa_id, num numero ");
		sql.append("from mesa ma ");
		sql.append("where ativa = 1 ");
		
		ArrayList<MesasAtivas> mesasAtivas = null;
		
		try {
			ps = DataBase.getConnectionDB().
					prepareStatement(sql.toString());
						
			ResultSet rs = ps.executeQuery();
			mesasAtivas = new ArrayList<MesasAtivas>();
			
			while (rs.next()) {
				ma = new MesasAtivas();
				ma.setId(rs.getInt("mesa_id"));
				ma.setNumero(rs.getInt("numero"));
				mesasAtivas.add(ma);
			}
		} catch (Exception e) {}
				
		return mesasAtivas;
	}
}
